$(document).ready(function () {

    console.log('search.js loaded');

    $(".drawNumber").keyup(function (e) {
        if (e.which === 13) {
            $('.searchDrawNumber').trigger('click');
        }
    });

    //$(".searchDrawNumber").click(function () { 
    //    window.location = UpdateQueryString("draw", $(".drawNumber").val(), window.location.href);

    //});
    ////pause-btn

    $(".pause-btn").click(function () {
        window.location.href = window.location.pathname;
    
    });
    
   $(".page-link").click(function () { 
        window.location = $(this).attr('href');

    });

    var drawNumber = getUrlParameter('query');

    if (drawNumber !== "" || drawNumber !== null) {
        $(".drawNumber").val(drawNumber);
    }

    function addOrReplaceKey(key, value) {
        var stringToAdd = key + "=" + value;

        if (window.location.search === "")
            return window.location.href + stringToAdd;

        if (window.location.search.indexOf(key) === -1)
            return window.location.href + stringToAdd;

        var newSearchString = "";
        var searchParams = window.location.search.substring(1).split("&");
        for (var i = 0; i < searchParams.length; i++) {
            if (searchParams[i].indexOf(key) > -1) {
                searchParams[i] = key + newData;
                break;
            }
        }
        return window.location.href.split("?")[0] + "?" + searchParams.join("&");
    }

    function getUrlParameter(sParam) {
        var sPageURL = window.location.search.substring(1),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;

        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');

            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
            }
        }
    }

    function UpdateQueryString(key, value, url) {
        if (!url) url = window.location.href;
        var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
            hash;

        if (re.test(url)) {
            if (typeof value !== 'undefined' && value !== null)
                return url.replace(re, '$1' + key + "=" + value + '$2$3');
            else {
                hash = url.split('#');
                url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
                if (typeof hash[1] !== 'undefined' && hash[1] !== null)
                    url += '#' + hash[1];
                return url;
            }
        } else {
            if (typeof value !== 'undefined' && value !== null) {
                var separator = url.indexOf('?') !== -1 ? '&' : '?';
                hash = url.split('#');
                url = hash[0] + separator + key + '=' + value;
                if (typeof hash[1] !== 'undefined' && hash[1] !== null)
                    url += '#' + hash[1];
                return url;
            } else
                return url;
        }
    }

});